<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<jsp:useBean id="loginBean" class="mybean.data.login" scope="session"/>

<!-- 用户可以通过选择地区修改单车停放地方，输入id对单车的状态进行修改，还车 -->
<!-- 这里要导处一个该id车辆的信息表，并提示归还成功 -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>return</title>
		<link rel="stylesheet" type="text/css" href="css/index-2.css">
		<link rel="stylesheet" type="text/css" href="css/index-1.css">
		<link rel="stylesheet" type="text/css" href="css/reset.css">
		<link rel="stylesheet" type="text/css" href="css/common.css">
</head>
<body>
	<%@ include file="head.txt" %>
	<div class="Admin-content" style="padding-top: 50px"><center>
		<form action="changeDistractServlet" method="post">如果单车所处的地区已经改变，请选择归还地区
			&nbsp;&nbsp;&nbsp;<select class="borrow-place" name="distract">
	<!-- 根据数据库生成下拉选项 -->
		<%	
		if(loginBean==null){
			out.println("<script language = javascript>alert('请重新登录!');");
			out.println("location.href='index.jsp'</script>");
			return;
			}
		else{
			boolean b=loginBean.getLogname()==null || loginBean.getLogname().length()==0;
			if(b){
				out.println("<script language = javascript>alert('请重新登录!');");
				out.println("location.href='index.jsp'</script>");
				return;
			}
		}		
		try {//加载驱动
    			Class.forName("com.mysql.cj.jdbc.Driver");
    		 }
    		catch(Exception e) {}
			String url = "jdbc:mysql://127.0.0.1:3306/bike?&useSSL=false&serverTimezone=GMT%2B8";
			Connection con;
         	Statement sql;
         	ResultSet rs;        
         	String condition = "select Dname FROM district";//查询出有车的地区
        	String id="",mess="";
         	try {//连接数据库
    			con = DriverManager.getConnection(url,"root","744615");
    			sql=con.createStatement();
    			//获得有单车的地区
    			rs = sql.executeQuery(condition);
    			while(rs.next()){
   				 String district=rs.getString("Dname");%>  <!--获取有单车的地区作为可选项-->
   				 <option value="<%=district %>" selected="selected"><%=district %></option>
   			<%	}
    			sql.close();
    			condition = "select * from orderform where username='"+loginBean.getLogname()+"'";//查询已借的车
    			sql=con.createStatement();
    			rs=sql.executeQuery(condition);
    			if(rs.next()==true){
    				id = rs.getString("id");
					mess = rs.getString("mess");    	
    			%>
    			 <input type="submit"  id="button" value='确定' class="submit">		  
			</select><br></form>	
    		<table border=2>
				<tr style="background-color: #004b97;color: white"><th width=80 height=40>单车编号</th><th width=300 height=40>单车信息</th><th width=80 height=40>还车</th></tr>
				<tr><td height=50><center><%=id %></center></td>
					<td height=50><center><%=mess %></center></td>
					<td height=50><center>
						<form action="returnServlet" method="post"> 
							<input type="hidden" name="delete" value="<%=mess %>">
							<input type="submit" value="还车" class="submit">
						</form></center></td>
				</tr><br>
			</table>
    		<%	}
    			else{   //订单中没有记录，说明该用户没有借车
    				out.println("<script language = javascript>alert('没有需要还的车，欢迎借车!');");
    				out.println("location.href='borrow.jsp'</script>");
				}
    			sql.close();
    			con.close();  
    		}
         	catch(SQLException e) {
         		System.out.println(e);
         	}
         	%></center>
		<div class="return-attention"><p>友情提示</p></div>
		<center><!-- 图片滚动条 --> 
    	<div id="bg2">  
        	<div id="sm2"> <!--滚动div-->  
                <table>       <!--外表格1x2,且第2单元格是空的-->  
                    <tr><td id="Pic1">  
                            <table> <tr>   <!--内表格1x3,存放3张图片-->                                  
                                    <td><img src="pictures/return-rule.jpg" onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td>
                                    <td><img src="pictures/rule.jpg" onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td> 
                                    <td><img src="pictures/rule3.jpg" onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td>  
                                    <td><img src="pictures/warn3.jpg" onmouseover="mouseover(this)" onmouseout="mouseout(this)"/></td>   
                                </tr>  
                           </table>  
                       </td>  <td id="Pic2"></td>  
                    </tr>  
                </table>  
        	</div>  
    	</div>  
 	</center></div>
	<script type="text/javascript">
	//滚动条
	 Pic2.innerHTML=Pic1.innerHTML;//复制一组图片，但被隐藏  
   	function scrolltoleft(){//定义向左移动的方法  
       sm2.scrollLeft++;//改变层的水平坐标，实现向左移动  
       if(sm2.scrollLeft>=Pic1.scrollWidth)//需要复位  
           sm2.scrollLeft=0;//层的位置复位，浏览器窗口的宽度有限的  
   	}      
   var MyMar=setInterval(scrolltoleft,40); //定时器，方法名后不可加()        
   function mouseover(x){//放大图片   
       x.style.cursor="pointer"  
   }   
   //两面两行是用方法响应对象的事件  
   sm2.onmouseover=function(){//匿名方法（函数）  
       clearInterval(MyMar);//停止滚动  
   }  
     
   sm2.onmouseout=function(){  
       MyMar = setInterval(scrolltoleft,40);//继续滚动  
   }  
	</script>
	<!--页面底部-->
	<!--所以的页面底部都一样，用一个文本文件存储，所有JSP文件使用嵌入-->
	<%@ include file="footer.txt" %>
</body>
</html>